/* Initial beliefs and rules */

/* Initial goals */
!locate(garbage).

/* Plans */

+!pause
<-  stop.

+!continue
<- removeStop.

+!locate(garbage) : coalition
<-	!clean(garbage).
	
+!locate(garbage) : stop & not at(garbage_pos)
<-	nop;
	!locate(garbage).

+!locate(garbage) : not at(garbage_pos)
<-	locate(closest_garbage);
	?lixo(closest_garbage, X, Y);
	.print("Lixo localizado");
	//.broadcast(achieve, pause);
	!coalition(X,Y).
	

-!locate(garbage) : true
<-	movetoexplore(newpos);
	!locate(garbage).

+!coalition(X,Y) : true
<-	//findCoalition(X,Y);
	.send(manager, tell, requestCoalition(X,Y));
	//.send(manager,askOne,location(closest_garbage, X, Y),A);
	removePerceptLixo(X,Y);
	//.broadcast(achieve, continue);
//	?coalition(A, X, Y); 
//	.send(A, tell, location(closest_garbage, X, Y));
	?location(closest_garbage, X, Y);
	!clean(garbage).

-!coalition(X,Y)
<-	!locate(garbage).

//coalition(a1) coalition(a2) coalition(a3)

+!clean(garbage) : not at(garbage_pos)
<-	.print("clean");
	?location(closest_garbage, X, Y);
	moveto(X, Y);
	!check(pos).
	
-!clean(garbage)
<-	nop;
	!locate(garbage).

+!check(pos) : at(objective_pos)
<-	?location(robot, X, Y);
	remove(garbage, X, Y);
	?location(closest_garbage, X, Y);
	//-at(objective_pos);
	!clean(garbage).
	//!locate(garbage).
	
-!check(pos) 
<-	!locate(garbage).

+!check(pos) : not at(objective_pos)
<-	update(pos);
	!check(pos).
    




